<template>
	<view class="">
		<view class="friends-info">
			<view class="flex align info-item">
				<view class="info-label">赠送人ID</view>
				<input type="number" class="info-input" placeholder="请输入ID" v-model="userid">
			</view>

			<view class="flex align info-item">
				<view class="info-label">转赠贡献值数量</view>
				<input type="number" class="info-input" placeholder="请输入个数" v-model="nums">
			</view>
		</view>
		<button class="btn" @click="ongGiveFriends">确认转赠</button>
		
		
		<pay-keyboard :show_key="show_pay_keyboard" @hideFun="hidePayKeyboard" :show_forget="true"
			@getPassword="getPayPassword"></pay-keyboard>
	</view>
</template>

<script>
	import {
		giveFriends,
		checkpaypwdRequest
	} from "../../api/index.js"
	export default {
		data() {
			return {
				show_pay_keyboard: false,
				payPassword: '',
				userid: '',
				name: '',
				nums: ''
			}
		},
		onLoad() {},
		methods: {
			async showPayKeyboard() {
				this.show_pay_keyboard = true
			},
			hidePayKeyboard() {
				this.show_pay_keyboard = false
			},
			async getPayPassword(n) {
				console.log("用户输入的密码", n)
				this.payPassword = n.password;
				this.show_pay_keyboard = false
			
				const res = await checkpaypwdRequest('s=/ApiMy/checkpaypwd', {
					paypwd: this.payPassword
				})
				const {
					id,
					status,
					msg
				} = res.data
			
				if (status == 1) {
					await this.onSub()
				} else {
					this.showToast(msg)
				}
			},
			async onSub() {
				const res = await giveFriends('s=/ApiZwyRequest/givefriends', {
					userid: this.userid,
					name: this.name,
					nums: this.nums
				})
				const {
					data,
					status,
					msg
				} = res.data
				console.log(res, "帮")
				this.showToast(msg)
				if (status == 1) {
					this.goBack(1500)
				} 
			},
			ongGiveFriends() {
				switch (true) {
					case this.userid == '':
						this.showToast('请输入赠送人ID')
						break;
					// case this.name == '':
					// 	this.showToast('请输入对方真实姓名~')
					// 	break;
					case this.nums == '':
						this.showToast('请输入转赠贡献值数量~')
						break;
					default:
						this.showPayKeyboard()


				}


			},

		}
	}
</script>

<style>
	page {
		background-color: #F7F7F7;
	}
</style>

<style lang="scss" scoped>
	.friends-info {
		margin: 20rpx 0;
		background-color: #FFF;
		line-height: 93rpx;
		font-size: 29rpx;

		.info-item {
			margin: 0 24rpx;

			.info-label {
				min-width: 200rpx;
			}

			.info-input {
				flex: 1;
				font-size: 27rpx;
				text-align: right;
			}
		}
	}

	.btn {
		margin: 98rpx 20rpx;
		background-color: #41644A;
		color: #FFF;
		line-height: 88rpx;
		border-radius: 20rpx;
	}
</style>
